package concurrency;

import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by duan lian on 2017-08-24.
 */
public class FailFastSafeIterator {
	public static void main(String[] args) {
		Map<String,String>  map=new ConcurrentHashMap<>();  // fail-safe
//		Map<String,String>  map=new HashMap<>();        // fail-fast
		map.put("a", "v1");
		map.put("b", "v2");
		map.put("c", "v3");


		Iterator<String> iter = map.keySet().iterator();
		while(iter.hasNext()) {
			System.out.println(iter.next());
			map.put("d", "v4");
		}

		System.out.println(map);
	}
}
